import {getCategoryAPI} from "@/apis/category.js";
import {onMounted, ref} from "vue";
import {onBeforeRouteUpdate, useRoute} from "vue-router";


export function useCategory(){
    const categoryData=ref({})
    const route=useRoute()
    const getCategoey=async (id=route.params.id)=>{
        const  res=await getCategoryAPI(id)
        categoryData.value=res.result
    }

    onMounted(()=>{
        getCategoey()
    })


    onBeforeRouteUpdate((to)=>{
        getCategoey(to.params.id)
    })

    return{
        categoryData
    }

}